package com.course.cdspringboot.mapper.achievement;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.course.cdspringboot.entity.achievement.AchievementPaper;
import com.course.cdspringboot.entity.achievement.AchievementPatent;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface AchievementPatentMapper extends BaseMapper<AchievementPatent> {

    @Select("SELECT count(*) FROM achievement_patent WHERE patent_name = #{patent_name}")
    int countByPatentName(String patentName);

    @Select("<script>" +
            "SELECT achievement_patent.*, review_status.name review_status, achievements.created_date, achievements.review_comments " +
            "FROM achievement_patent " +
            "JOIN achievements ON achievement_patent.achievement_id = achievements.achievement_id " +
            "JOIN review_status ON achievements.review_status_id = review_status.id " +
            "WHERE achievements.is_deleted=false AND achievement_patent.achievement_id IN " +
            "<foreach item='item' index='index' collection='ids' " +
            "open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<AchievementPatent> selectByAchievementIds(@Param("ids") List<Integer> ids);



//    // 插入专利
//    @Insert("INSERT INTO achievement_patent (achievement_id, patent_name, patent_property, patent_type, " +
//            "authorization_status, application_number, publication_number, authorization_number, " +
//            "inventors, patent_owner, application_date, authorization_date, patent_certificate, submission_date) " +
//            "VALUES (#{achievement_id}, #{patent_name}, #{patent_property}, #{patent_type}, " +
//            "#{authorization_status}, #{application_number}, #{publication_number}, #{authorization_number}, " +
//            "#{inventors}, #{patent_owner}, #{application_date}, #{authorization_date}, #{patent_certificate}, #{submission_date})")
//    void insertAchievementPatent(Map<String, Object> achievementPatent);

//    @Update("UPDATE achievement_patent " +
//            "SET patent_name = #{patent_name}, " +
//            "    patent_property = #{patent_property}, " +
//            "    patent_type = #{patent_type}, " +
//            "    authorization_status = #{authorization_status}, " +
//            "    application_number = #{application_number}, " +
//            "    publication_number = #{publication_number}, " +
//            "    authorization_number = #{authorization_number}, " +
//            "    inventors = #{inventors}, " +
//            "    patent_owner = #{patent_owner}, " +
//            "    application_date = #{application_date}, " +
//            "    authorization_date = #{authorization_date}, " +
//            "    patent_certificate = #{patent_certificate}, " +
//            "    submission_date = #{submission_date} " +
//            "WHERE achievement_id = #{achievement_id} AND " +
//            "achievement_id IN (SELECT achievement_id FROM achievements WHERE Owner=#{uid});")
//    void updatePatent(Map<String, Object> achievement_patent_info);
}
